﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControls_ucPicBrowse : System.Web.UI.UserControl
{
    private string strImageFolderName = "";
    public string ImageFolderName
    {
        get { return strImageFolderName; }
        set { strImageFolderName = value; }
    }
    public string contentHtml = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetHtml();
        }
    }

    public List<string> GetImageName(string strServerImagePath)
    {
        List<string> lstImageFiles = new List<string>();
        DirectoryInfo imagesfile = new DirectoryInfo(strServerImagePath);
        FileSystemInfo[] arrFiles = imagesfile.GetFiles("*.*");

        for (int i = 0; i < arrFiles.Length; i++)
        {
            string strFileExt = arrFiles[i].Extension.ToUpper();
            if (strFileExt == ".JPG" || strFileExt == ".JPEG" || strFileExt == ".BMP" || strFileExt == ".PNG" || strFileExt == ".GIF")
            {
                lstImageFiles.Add(arrFiles[i].Name);
            }
        }
        return lstImageFiles;
    }

    public string GetImageUrl()
    {
        return Server.MapPath(strImageFolderName);
    }

    protected void GetHtml()
    {
        string strServerImagePath = GetImageUrl();
        List<string> arrImageUrl = GetImageName(strServerImagePath);

        for (int i = 0; i < arrImageUrl.Count; i++)
        {
            contentHtml += string.Format("<li><a class='thumb' name='leaf_{0}' href='{3}/{1}' title='{1}'><img src='{3}/{1}' alt='{1}' height='60' width='90' /></a><div class='caption'><div class='download'><a href='{2}\\{1}'>下载</a></div><div class='image-title'>{1}</div> <div class='image-desc'>图片描述：{1}</div></div></li>", i, arrImageUrl[i], strServerImagePath,strImageFolderName);
        }

    }
}